import React, {Component} from 'react';
import {
    View,
    StyleSheet,
    Image,
    Text,
    TouchableOpacity,
    ScrollView,
    Animated,
    PanResponder,
    Easing,
    Alert,
    DeviceEventEmitter
} from 'react-native';
import { Toast,Button,WingBlank,WhiteSpace} from 'antd-mobile-rn';
import { inject, observer } from 'mobx-react';

@inject("mottoStore")
@observer
export default class Mine extends Component {
    constructor(props){
        super(props);
        this.motto = this.props.mottoStore;
    }
    GetData(){
        Toast.loading('loading...',0);//显示loading
        this.motto.GetSingleMotto();//发起网络请求
    }
    
    componentDidMount(){
        let that = this;
        //监听请求完成事件
        this.subscription = DeviceEventEmitter.addListener('loadMottoComplete',() => {
            Toast.hide();
            // setTimeout(() => {
            //     that.motto.MottoData = {
            //         motto_Content:'123456',
            //         auth_Name:'456789'
            //     }
            // },3000)
            // setTimeout(() => {
            //     that.motto.IsLoaded = false
            // },5000)
        })
        this.GetData();
    }
    componentWillUnmount(){
        this.subscription.remove();//移除消息监听
    }
    render(){
        return(
            <WingBlank>
                <WingBlank>
                {
                    this.motto.IsLoaded && (
                        <View>
                            <Text>{this.motto.MottoData.motto_Content}</Text>
                            <Text>————{this.motto.MottoData.auth_Name}</Text>
                        </View>
                    )
                }
                <Button type="primary" onClick={() =>{
                    this.GetData();
                }}>刷新</Button>
                </WingBlank>
            </WingBlank>
        )
    }
}